package com.yellowpage.omc.o2o.service;

import java.util.List;
import java.util.Map;

import org.springframework.transaction.TransactionDefinition;
import org.springframework.transaction.TransactionStatus;
import org.springframework.transaction.support.DefaultTransactionDefinition;

import com.yellowpage.white.common.Constants;
import com.yellowpage.white.common.PageRender;
import com.yellowpage.white.dao.QueryAssistantSQL;
import com.yellowpage.white.service.BaseServiceImpl;

import com.yellowpage.omc.o2o.data.ChannelCustomer;
import com.yellowpage.omc.o2o.dao.ChannelCustomerDao;

public class ChannelCustomerServiceImpl extends BaseServiceImpl implements ChannelCustomerService {
	  private ChannelCustomerDao channelCustomerDao;
	
	  public void setChannelCustomerDao(ChannelCustomerDao channelCustomerDao) {
		  this.channelCustomerDao = channelCustomerDao;
	  }
	
	
	  /* Smooth generate Method */ 
	  public ChannelCustomer getChannelCustomer(Long id){
	      return channelCustomerDao.get(id);
	  }
	  
    public List<ChannelCustomer> getAllChannelCustomer(){
        return channelCustomerDao.getAll();
    }
    
    public List<Map> queryChannelCustomerByPage(Map queryMap, PageRender pageRender) {		
        
		QueryAssistantSQL sqlAssistant = baseDao.newQueryAssistantSQL(
				"SELECT a.CHANNEL_CUSTOMER_ID , a.CUSTOMER_ID , a.CHANNEL_ID , a.LAST_ORDER , (select display_name from CA_USER where user_id = a.CREATE_USER) as CREATE_USER , a.CREATE_TIME , (select display_name from CA_USER where user_id = a.LAST_UPDATE_USER) as LAST_UPDATE_USER , a.LAST_UPDATE_TIME    FROM OMC_CHANNEL_CUSTOMER a WHERE 1=1 ")
				    			.addCondition(" and CHANNEL_CUSTOMER_ID = :channelCustomerId ")
							    			.addCondition(" and CUSTOMER_ID = :customerId ")
							    			.addCondition(" and CHANNEL_ID = :channelId ")
							    			.addCondition(" and LAST_ORDER = :lastOrder ")
							    			.addCondition(" and CREATE_USER = :createUser ")
							    		    .addCondition(" and date_format(CREATE_TIME,'%Y-%m-%d') =  :createTime  ")
		    				    			.addCondition(" and LAST_UPDATE_USER = :lastUpdateUser ")
							    		    .addCondition(" and date_format(LAST_UPDATE_TIME,'%Y-%m-%d') =  :lastUpdateTime  ")
		    				    ; 		    
		    

		List<Map> resultList = sqlAssistant.queryByPage(
				baseDao.getConnection(), queryMap, pageRender);

		return resultList;
	}
    
    
    public void saveChannelCustomer(ChannelCustomer channelCustomer){
        channelCustomerDao.save(channelCustomer);
    }
    
	  public void updateChannelCustomer(ChannelCustomer channelCustomer){
	      channelCustomerDao.update(channelCustomer);
	  }
	  
	  public void delete(List deleteList){
	      channelCustomerDao.remove(deleteList);
	  }
	  
	  
	 
	
}	